{extend name="public:base" /}
{block name="head"}
<link href="__PUBLIC__/view_res/mobile/css/wshop_companyreg.css" type="text/css" rel="Stylesheet" />
<link href="__PUBLIC__/jquery-weui/dist/lib/weui.min.css" type="text/css" rel="Stylesheet" />
<link href="__PUBLIC__/jquery-weui/dist/css/jquery-weui.min.css" type="text/css" rel="Stylesheet" />
<link rel="stylesheet" href="/public/static/js/bt/bootstrap.min.css" />
<link rel="stylesheet" href="/public/static/font-awesome/4.7.0/css/font-awesome.min.css" />
        <!-- ace styles -->

<link type="image/x-icon" href="/public/uploads/cache/images/osc1/logo/qrcode_7-16x15.jpg" rel="icon">
<link type="image/x-icon" href="/public/uploads/cache/images/osc1/logo/qrcode_7-16x15.jpg" rel="bookmark">

<script src="__PUBLIC__/jquery-weui/dist/js/jquery-weui.min.js"></script>
<script src="/public/static/js/jquery/jquery-2.1.4.min.js"></script>
<script src="/public/static/js/jquery/jquery-migrate-1.2.1.min.js"></script>
            
        
<script src="/public/static/artDialog/artDialog.js"></script>
<link href="/public/static/artDialog/skins/default.css" rel="stylesheet" type="text/css" />         
        
<script>
            
</script>
<script src="/public/static/js/oscshop_common.js"></script>
<link href="__PUBLIC__/view_res/mobile/css/wshop_company_center.css" type="text/css" rel="Stylesheet" />
<link href="__PUBLIC__/view_res/mobile/css/uc.css" type="text/css" rel="Stylesheet" />

{/block} 

{block name="header"}
{include file="public/top-nav" /}
{/block}

{block name="content"}   
<style>
/*.user{
    position: relative;
    color: #444;
    padding-left: 20px;
    line-height: 30px;
    font-size: 14px;

    border-bottom: 1px solid #eee;
    background: url(../images/icon_bar-right.png) 97.5% center no-repeat #fefefe;
    background-size: 15px 16px;
    display: block;
    outline: none;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);}*/
table tr{

    position: relative;
    color: #444;
    padding-left: 50px;
    line-height: 40px;
    font-size: 14px;
    background: url(../images/icon_bar-right.png) 97.5% center no-repeat #fefefe;

}
td{padding-left: 18px;}
</style>
<!-- from -->

<form  action="/mobile/financing/frist_rang_sell" id="from1" method="post">
   {:token()}
    <!--
    {if condition="1 eq $endflag"}  
    <a class="button red" href="/mobile/financing/special" id="reg-btn">按要求挂单交易未成功，需特殊处理</a>
    {/if}
-->
<div style="height: 30pt; line-height: 30pt; text-align: center; background: #fff; color: #f00; border-top: 1px solid #f00; border-bottom: 1px solid #f00;">
    {if condition="0 eq $rang_order[0]['sell_state']"}操作指导已经下发，请按照以下指导操作{/if}
    {if condition="1 eq $rang_order[0]['sell_state']"}
    卖出凭证已经提交,
    {if condition="1 eq $rang_order[0]['buy_state']"}
    待管理员审核
    {/if}
    {if condition="0 eq $rang_order[0]['buy_state']"}
    等待买入凭证提交
    {/if}
    {if condition="3 eq $rang_order[0]['buy_state']"}
    等待买入凭证提交
    {/if}

    {/if}
    {if condition="2 eq $rang_order[0]['sell_state']"}审核通过,本轮完成，请继续下一轮{/if} 
    {if condition="3 eq $rang_order[0]['sell_state']"}审核不通过{/if}
</div>
<!--     <header class="Thead">当前状态</header> -->
<p style="height: 30pt; line-height: 30pt; margin-top: 10px; background: #37485c;">
    <a style="margin-left:30px; font-size: 16px; color: #fff;"><strong>卖出操作指导</strong></a>
</p>  
<!--     <header class="Thead">卖出交易指令</header> -->
    <div>
        <b style="height: 37px; line-height: 37px; display: block; float: left; border-top: 1px solid #DEDEDE; border-bottom: 1px solid #DEDEDE; background: #FFFFFF; padding-left: 30px;">卖出时间：</b>
        <div class="gs-text">
            <input type="text" name="" value="请于{$rang_order[0]['sell_time']}前"  placeholder="卖出时间" >
        </div>
    </div>

    <div style="height: 37px; line-height: 37px;border-top: 1px solid #DEDEDE; border-bottom: 1px solid #DEDEDE; background: #FFFFFF; margin-bottom: 8px;">
        <b style="padding-left: 30px;">交易所：</b>
            <span>
                {volist name="exchange" id="p" empty="$exchange"}
                        {if condition="$p.id eq $rang_order[0]['exchange_id']"}{$p.name}{/if}              
                    {/volist}
            </span>
    </div>

    <div>
        <b style="height: 37px; line-height: 37px; display: block; float: left; border-top: 1px solid #DEDEDE; border-bottom: 1px solid #DEDEDE; background: #FFFFFF; padding-left: 30px;">交易所主账号：</b>
        <div class="gs-text">
            <input type="text" name="" value="{$rang_order[0]['trade_id']}"  placeholder="交易所主账号" >
        </div>
    </div>
    <div>
        <b style="height: 37px; line-height: 37px; display: block; float: left; border-top: 1px solid #DEDEDE; border-bottom: 1px solid #DEDEDE; background: #FFFFFF; padding-left: 30px;">交易所副账号：</b>
        <div class="gs-text">
            <input type="text" name="" value="{$rang_order[0]['sub_trade_id']}"  placeholder="交易所副账号" >
        </div>
    </div>
    <div style="height: 37px; line-height: 37px;border-top: 1px solid #DEDEDE; border-bottom: 1px solid #DEDEDE; background: #FFFFFF; margin-bottom: 8px;">
        <b style="padding-left: 30px;">交易品种：</b>
            <span color="green">
               {volist name="variety" id="p" empty="$variety"}
                        {if condition="$p.id eq $rang_order[0]['exchange_variety_id']"}{$p.name}{/if}              
                    {/volist} 
            </span>
    </div>
    <div>
        <b style="height: 37px; line-height: 37px; display: block; float: left; border-top: 1px solid #DEDEDE; border-bottom: 1px solid #DEDEDE; background: #FFFFFF; padding-left: 30px;">交易品种编码：</b>
        <div class="gs-text">
            <input type="text" name="" value="{$rang_order[0]['variety_id']}"  placeholder="交易品种编码" >
        </div>
    </div>
    <div>
        <b style="height: 37px; line-height: 37px; display: block; float: left; border-top: 1px solid #DEDEDE; border-bottom: 1px solid #DEDEDE; background: #FFFFFF; padding-left: 30px;">数量：</b>
        <div class="gs-text">
            <input type="text" name="" value="{$rang_order[0]['sell_num']}枚"  placeholder="数量" >
        </div>
    </div>
    <div>
        <b style="height: 37px; line-height: 37px; display: block; float: left; border-top: 1px solid #DEDEDE; border-bottom: 1px solid #DEDEDE; background: #FFFFFF; padding-left: 30px;">挂单价格：</b>
        <div class="gs-text">
            <input type="text" name="" value="￥{$rang_order[0]['sell_price']}"  placeholder="" >
        </div>
    </div>
    <div>
        <b style="height: 37px; line-height: 37px; display: block; float: left; border-top: 1px solid #DEDEDE; border-bottom: 1px solid #DEDEDE; background: #FFFFFF; padding-left: 30px;">卖出总价：</b>
        <div class="gs-text">
            <input type="text" name="" value="￥{$rang_order[0]['sell_price']*$rang_order[0]['sell_num']}"  placeholder="卖出总价" >
        </div>
    </div>
   
{if condition="3 eq $rang_order[0]['sell_state']"}
    <header class="Thead">审批意见</header>
    <div style="padding:0 10px;">
        <div class="gs-text">
            <textarea readonly="true" style="width: 100%;" rows="4">{$rang_order[0]['desc']}</textarea>
           
        </div>
    </div>
    {/if}   
   
<div style="height: 30pt; line-height: 30pt; background: #37485c;">
    <a style="margin-left:10px; font-size: 14px; color: #fff;"><strong>图片上传(图片最大5M,最多3张)</strong></a>
</div>   

<div id="1" class="gs-text">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            {if condition="0 eq $rang_order[0]['sell_state']"} 
            <div class="col-sm-3">
                <a href="/mobile/financing/frist" data-toggle="tooltip" title="刷新" id="button-refresh" class="btn btn-default">刷新
                    <i class="fa fa-refresh"></i>
                </a>

                <button type="button" data-toggle="tooltip" title="上传" id="button-upload" class="btn btn-primary">上传
                    <i class="fa fa-upload"></i>
                </button>
                <button type="button" data-toggle="tooltip" title="删除" id="button-delete" class="btn btn-danger">删除
                    <i class="fa fa-trash-o"></i>
                </button>
            </div>
            {/if}
            {if condition="3 eq $rang_order[0]['sell_state']"} 
            <div class="col-sm-3">
                <a href="/mobile/financing/frist" data-toggle="tooltip" title="刷新" id="button-refresh" class="btn btn-default">刷新
                    <i class="fa fa-refresh"></i>
                </a>
                <button type="button" data-toggle="tooltip" title="上传" id="button-upload" class="btn btn-primary">上传
                    <i class="fa fa-upload"></i>
                </button>
                <button type="button" data-toggle="tooltip" title="删除" id="button-delete" class="btn btn-danger">删除
                    <i class="fa fa-trash-o"></i>
                </button>
            </div>
            {/if}
            <table id='1' width="100%" height="214" border="0" cellpadding="0" cellspacing="1">
                <input type="hidden" name="id" id="id" value="{$rang_order[0]['id']}"/>
                <?php if(!empty($img)){ ?>
                <?php foreach ($img as $image) { ?>
                <tr>
                    <td width="50%" align="right">
                        <div class="col-sm-1 text-center">
                            <a href="<?php echo $image['img_path']; ?>"  class="">
                                <img height="120" width="120" src="<?php echo $image['img_path']; ?>" alt="<?php echo $image['file_name']; ?>" title="<?php echo $image['file_name']; ?>" />
                            </a>
                    </td>
                    <td width="50%" align="left">
                        <label>
                            <input type="checkbox" name="path[]" value="<?php echo $image['img_path']; ?>" />
                            <?php echo $image['file_name']; ?>
                        </label>
                          
                    </td>
                </tr>
                <?php } ?>
                <?php } ?>
            </table>

      </div>
    </div>
</div>
{if condition="0 eq $rang_order[0]['sell_state']"} 
<input type="submit"   class="button blue bigrounded" style="width:100%;margin:0 auto; color: #fff!important; position:relative;" value="提交第一轮卖出凭证"/>
{/if}

{if condition="3 eq $rang_order[0]['sell_state']"}  
<div id="appCartWrap" class="clearfix">  
<input type="submit" class="button blue bigrounded" style="width:100%;margin:0 auto; color: #fff!important; position:relative;" value="重新提交第一轮卖出凭证"/>
{/if}

{if condition="2 eq $rang_order[0]['state']"} 
<p style="height: 30pt; line-height: 30pt; text-align: center; background: #37485c;"> 
<a href="/mobile/second/frist" style="color: #fff;">当前轮次已经走完，请进入下一轮</a>
</p>
{/if}
</div>

</form>


{/block}
{block name="script"}
<script>
$('#reg-btn').click(function(){
    $.post(
            '{:url("financing/frist")}',    
        $('input[type="text"],input[type="select"],input[type="hidden"]'),
        function(d){
            if(d.error){
                $.toast(d.error, "forbidden");
            }else if(d.success){
                $.toast(d.success);
                //sleep(500);
                             
            }
        }
    );
});

function fileSelected() {
            var file = document.getElementById('fileToUpload').files[0];
            if (file) {
                var fileSize = 0;
                if (file.size > 1024 * 1024)
                    fileSize = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';
                else
                    fileSize = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';
 
                document.getElementById('fileName').innerHTML = 'Name: ' + file.name;
                document.getElementById('fileSize').innerHTML = 'Size: ' + fileSize;
                document.getElementById('fileType').innerHTML = 'Type: ' + file.type;
            }
        }
 
        function uploadFile() {
            var fd = new FormData();
            fd.append("fileToUpload", document.getElementById('fileToUpload').files[0]);
            var xhr = new XMLHttpRequest();
            xhr.upload.addEventListener("progress", uploadProgress, false);
            xhr.addEventListener("load", uploadComplete, false);
            xhr.addEventListener("error", uploadFailed, false);
            xhr.addEventListener("abort", uploadCanceled, false);
            xhr.open("POST", "Home/Upload");
            xhr.send(fd);
        }
 
        function uploadProgress(evt) {
            if (evt.lengthComputable) {
                var percentComplete = Math.round(evt.loaded * 100 / evt.total);
                document.getElementById('progressNumber').innerHTML = percentComplete.toString() + '%';
            }
            else {
                document.getElementById('progressNumber').innerHTML = 'unable to compute';
            }
        }
 
        function uploadComplete(evt) {
            /* This event is raised when the server send back a response */
            alert(evt.target.responseText);
        }
 
        function uploadFailed(evt) {
            alert("There was an error attempting to upload the file.");
        }
 
        function uploadCanceled(evt) {
            alert("The upload has been canceled by the user or the browser dropped the connection.");
        }   





$('a.directory').on('click', function(e) {
    e.preventDefault();

    $('#modal-image').load($(this).attr('href'));
});
$('.pagination a').on('click', function(e) {
    e.preventDefault();

    $('#modal-image').load($(this).attr('href'));
});
$('#button-parent').on('click', function(e) {
    e.preventDefault();

    $('#modal-image').load($(this).attr('href'));
});

$('#button-refresh').on('click', function(e) {
    e.preventDefault();
    //alert('===');

    //$('#modal-image').load($('#button-refresh').attr('href'));
    window.location.reload();
});

$('input[name=\'search\']').on('keydown', function(e) {
    if (e.which == 13) {
        $('#button-search').trigger('click');
    }
});




$('#button-upload').on('click', function() {

    $('#form-upload').remove();

    $('body').prepend('<form enctype="multipart/form-data" id="form-upload" style="display: none;"><input type="file" name="file" value="" /></form>');

    $('#form-upload input[name=\'file\']').trigger('click');

    if (typeof timer != 'undefined') {
        clearInterval(timer);
    }

    timer = setInterval(function() {
        if ($('#form-upload input[name=\'file\']').val() != '') {
            clearInterval(timer);

            var fromdata = new FormData($('#form-upload')[0]);
            //formData.append($('#form1'));
            //var checkValue=$("#exchange_id").val();
            //alert(checkValue);
            var checkValue = jQuery("#exchange_id").val();
            //alert(checkValue);
            fromdata.append("exchange_id",checkValue);
            fromdata.append("type",1);
            
            fromdata.append("id",{$rang_order[0]['id']});
            fromdata.append("rang_num",1);
            fromdata.append("rang",1);
            fromdata.append("trade_no",$("input[name='trade_no']").val());
            fromdata.append("trade_dt",$("input[name='trade_dt']").val());
            $.ajax({
                url: "/mobile/financing/upload",
                type: 'post',
                dataType: 'json',
                data: fromdata,
                cache: false,
                contentType: false,
                processData: false,
                beforeSend: function() {
                    $('#button-upload i').replaceWith('<i class="fa fa-circle-o-notch fa-spin"></i>');
                    $('#button-upload').prop('disabled', true);
                },
                complete: function() {
                    $('#button-upload i').replaceWith('<i class="fa fa-upload"></i>');
                    $('#button-upload').prop('disabled', false);
                },
                success: function(json) {
                    if (json['error']) {
                        alert(json['error']);
                    }

                    if (json['success']) {
                        alert(json['success']);

                        $('#button-refresh').trigger('click');
                    }
                },
                error: function(xhr, ajaxOptions, thrownError) {
                    alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                }
            });
        }
    }, 500);
});



$('#button-delete').on('click', function(e) {
    if (confirm('是否要删除')) {
        $.ajax({
            url: "<?php echo $data['delete_url']; ?>",
            type: 'post',
            dataType: 'json',
            data: $('input[name^=\'path\']:checked,input[type="hidden"]'),
            beforeSend: function() {
                $('#button-delete').prop('disabled', true);
            },
            complete: function() {
                $('#button-delete').prop('disabled', false);
            },
            success: function(json) {
                if (json['error']) {
                    alert(json['error']);
                }

                if (json['success']) {
                    alert(json['success']);

                    $('#button-refresh').trigger('click');
                }
            },
            error: function(xhr, ajaxOptions, thrownError) {
                alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
            }
        });
    }
});
</script>

<script type="text/javascript">
    
        {notempty name='error'}
        
            alert('{$error}');
            window.location.href="/mobile/financing/frist_rang_sell";
        
        {/notempty}
</script>

{/block}